package com.sdp.right.control;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sdp.core.bizc.db.Query;
import com.sdp.core.bizc.vo.DataCenter;
import com.sdp.core.bizc.vo.Result;
import com.sdp.right.db.sys_rdp_report.service.ISysRdpReportService;
import com.sdp.right.entity.SysRdpReport;
import com.sdp.right.utils.RightConstants;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zsp
 * @since 2023-10-19
 */
@RestController
@RequestMapping("/SysRdpReportController")
public class SysRdpReportController {
	
	@Autowired
	private Query query;
	
	@Autowired
	private ISysRdpReportService iSysRdpReportService;
	
	@PostMapping(value = "/page")
	public Result<?> page(@RequestBody DataCenter dataCenter) {
		return Result.ok(query.list(iSysRdpReportService, SysRdpReport.class,dataCenter));
	}
	
	@PostMapping(value = "/save")
	@Transactional(rollbackFor=Exception.class)
	public Result<?> save(@RequestBody SysRdpReport sysRdpReport) {
		if(sysRdpReport==null) {
			return Result.error("报表信息不存在");
		}
		
		if(StringUtils.isEmpty(sysRdpReport.getSystemNo())) {
			return Result.error("系统编号不存在");
		}
		
		if(StringUtils.isEmpty(sysRdpReport.getReportMenu())) {
			return Result.error("报表绑定的菜单信息不存在");
		}
		
		if(StringUtils.isEmpty(sysRdpReport.getKeyId())) {
			sysRdpReport.setIsUse(RightConstants.是.getCode());
			iSysRdpReportService.save(sysRdpReport);
		}else {
			iSysRdpReportService.updateById(sysRdpReport);
		}
		return Result.ok(sysRdpReport);
	}
	
	
	@GetMapping(value = "/del")
	@Transactional(rollbackFor=Exception.class)
	public Result<?> del(@RequestParam(name="keyId",required=true) String keyId) {
		if(StringUtils.isEmpty(keyId)) {
			return Result.error("需要删除的报表的主键不存在");
		}
		iSysRdpReportService.removeById(keyId);
		return Result.ok();
	}
	
	
}

